import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/config/home_images.dart';
import 'package:get/get.dart';
import 'package:juming_test/module/home/home/home_logic.dart';
import 'package:juming_test/module/home/home/widgets/home_banner.dart';
import 'package:juming_test/module/home/home/widgets/home_header_delegate.dart';
import 'package:juming_test/module/home/home/widgets/home_domain_data.dart';
import 'package:juming_test/module/home/home/widgets/home_kingkong.dart';
import 'package:juming_test/module/home/home/widgets/home_finance.dart';
import 'package:juming_test/module/home/home/widgets/home_notice.dart';
import 'package:juming_test/module/home/home/widgets/home_quick_section.dart';

@RoutePage()
class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final HomeLogic homeLogic = Get.put(HomeLogic());
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFF1A82F5), Color(0xFF1563E7)],
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
        ),
      ),
      child: SafeArea(
        child: CustomScrollView(
          slivers: [
            // 头部
            SliverPersistentHeader(
              pinned: true,
              delegate: HomeHeaderDelegate(
                expandedHeight: 110.h,
                shrinkHeight: 44.h,
              ),
            ),
            // 域名数据模块
            SliverToBoxAdapter(
              child: Obx(() {
                final domainData = homeLogic.domainViewModel.domainData.value;
                final showAllData = homeLogic.showAllData.value;

                return HomeDomainData(
                  domainData: domainData,
                  showAllData: showAllData,
                  foldAction: () => homeLogic.foldAction(),
                );
              }),
            ),
            SliverToBoxAdapter(
              child: Container(
                height: 12.w,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage(HomeImages.homeBodyHeaderPng),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
            ),
            // 快捷入口模块
            SliverToBoxAdapter(child: HomeQuickSection()),
            // 金刚位模块
            SliverToBoxAdapter(
              child: Obx(() {
                final list = homeLogic.kingkongViewModel.normalList.value;
                return HomeKingkong(kingkongList: list);
              }),
            ),
            // 公告栏模块
            SliverToBoxAdapter(
              child: Obx(() {
                final list = homeLogic.noticeViewModel.noticeList.value;
                return HomeNotice(noticeList: list);
              }),
            ),
            // banner模块
            SliverToBoxAdapter(
              child: Obx(() {
                final list = homeLogic.bannerViewModel.bannerList.value;
                return HomeBanner(bannerList: list);
              }),
            ),
            // 财务中心模块
            SliverToBoxAdapter(child: HomeFinance()),
          ],
        ),
      ),
    );
  }
}
